package org.dromara.house.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.house.domain.bo.ParkContractBo;
import org.dromara.house.domain.entity.ParkContract;
import org.dromara.house.domain.entity.ParkContractCheckOut;
import org.dromara.house.service.ParkContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 园区租赁合同表 前端控制器
 * </p>
 *
 * @author LCH
 * @since 2025-08-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/park/contract")
public class ParkContractController extends BaseController {

    @Autowired
    private ParkContractService service;

    /**
     * 获取角色信息列表
     */
    @SaCheckPermission("park:contract:list")
    @GetMapping("/list")
    public TableDataInfo<ParkContract> list(ParkContractBo bo, PageQuery pageQuery) {
        return service.selectPageContractList(bo, pageQuery);
    }


    /**
     * id获取详细信息
     *
     * @param id
     */
    @SaCheckPermission("system:contract:query")
    @GetMapping(value = "/{id}")
    public R<ParkContract> getInfo(@PathVariable Long id) {
        return R.ok(service.selectById(id));
    }

    /* *
     * 新增园区租赁合同
     */
    @SaCheckPermission("system:contract:add")
    @Log(title = "园区租赁合同管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody ParkContract parkContract) {
        return service.insertContract(parkContract);

    }

    /* *
     * 修改园区租赁合同
     *
     */
    @SaCheckPermission("system:contract:edit")
    @Log(title = "园区租赁合同管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public R<Void> edit(@Validated @RequestBody ParkContract parkContract) {
        return service.updateContract(parkContract);
    }


    /**
     * 删除园区租赁合同
     **/
    @SaCheckPermission("system:contract:remove")
    @Log(title = "园区租赁合同管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        return toAjax(service.deleteByIds(ids));
    }

    /**
     ParkContractCheckOut
     * 退租
     */
    @SaCheckPermission("system:contract:edit")
    @Log(title = "园区租赁合同管理", businessType = BusinessType.UPDATE)
    @PostMapping("/checkOut")
    public R<Void> checkOut(@Validated @RequestBody ParkContractCheckOut parkContractCheckOut) {
        return toAjax(service.checkOut(parkContractCheckOut));
    }
}

